/**
 * Created by zhangwenlei on 2017/5/9.
 */

ADF.control.ButtonGroup = function() {
    ADF.control.ButtonGroup.superclass.constructor.call(this);
};
COM.util.defineClass(ADF.control.ButtonGroup, ADF.CompositeDescriptor, {

    getEditpart: function() {
        var editpart = function() {
            editpart.superclass.constructor.call(this);
        };
        COM.util.defineClass(editpart, ADF.editpart.BaseEditpart, {
            _createFigure: function() {
                var buttonGroupFigure = new ADF.figure.ButtonGroupFigure();
                var buttonGroup = this.getWidgetFactory().createControl(this.getModel());
                buttonGroupFigure.setWidget(buttonGroup);
                return buttonGroupFigure;
            },
            createEditPolicies: function() {
                editpart.superclass.createEditPolicies.call(this);
                this.installEditPolicy(COM.gef.EditPolicy.LAYOUT_ROLE, new ADF.policy.ButtonGroupPolicy());
            },
            getModelChildren: function(){
                var composite = this.getModel();
                return composite.getChildren();
            },
            refreshVisuals: function( ) {
                var widgetBounds = this.getFigure().getWidget().getBounds();
                this.getFigure().setPreferredSize(new COM.draw2d.Dimension(widgetBounds.width, widgetBounds.height));
            },
            updateConstraint: function(bounds) {
                var constrain = new COM.draw2d.Rectangle(bounds.x, bounds.y, bounds.width, bounds.height);
                this.getParent().getFigure().setConstraint(this.getFigure(), constrain);
            },
            propertyChange: function(evt) {
                editpart.superclass.propertyChange.call(this, evt);
                var prop = evt.getPropertyName();
                if("children" == prop) {
                    this.refreshChildren();
                }
            }
        });
        return editpart;
    },

    getModel: function() {
        return ADF.model.ButtonGroupModel;
    },

    getDomControl : function(){
        return ADF.domControl.ButtonGroup;
    }

});